GBML manual / Input

action_rebind

Makes the action mean one button from now on - the way a controls screen lets a player choose. It replaces every button the action had, so afterwards only `b` counts.

Syntax

action_rebind(a, b)

Arguments

NameType
aaction
bbutton

Returns

Nothing.

Description

Makes an action mean one button from now on - what a controls screen does when the player picks a new key for something. It replaces every button the action had, so afterwards only the button you name counts. Every action_held, action_pressed and action_released of that action follows at once, and none of them needs to change.

The button is one of the BTN_* constants, such as BTN_A. The action is one of the names from Project Settings.

The new button lasts until the game is turned off. Nothing is saved for you. If a rebinding should still be there next time, your own code has to save the choice and call action_rebind again when the game starts. action_reset puts the buttons from Project Settings back.

Example

if (btn_pressed(BTN_SELECT)) {
    action_rebind(fire, BTN_R);
}

Pressing SELECT moves fire onto the R button. From the next check on, R fires and A does not, if A was what Project Settings gave it.

On the GBA

The engine keeps the mapping for the rest of this run only: a rebinding is gone the next time the game starts, unless your own code saves the choice (save_set) and calls action_rebind() again at startup. action_reset() puts the authored buttons back.

See also: action_resetaction_heldaction_pressedProject settingsBTN_A